#include "gtest/gtest.h"
#include "DataStructure/Common/Constant.h"
#include "../../IntegrationFormula/Gauss2D2X2P.h"
#include "../Plane4NodeIncomShpFunc.h"

using SG::DataStructure::Common::TOLERANCE;
using SG::Algebra::Matrixd;
using SG::FEMSolver::Element::Plane4NodeIncomShpFunc;

// 测试非协调形函数导数
TEST (Plane4NodeIncomShpFuncTest, shpFuncDerivativeTest)
{
    // Input
    SG::DataStructure::FEM::IntegPointArray integs (4);
    integs[0].m_x = -1.0; integs[0].m_y = -1.0;
    integs[1].m_x =  1.0; integs[1].m_y = -1.0;
    integs[2].m_x =  1.0; integs[2].m_y =  1.0;
    integs[3].m_x = -1.0; integs[3].m_y =  1.0;
    
    // Test data
    auto shpfunc = Plane4NodeIncomShpFunc ();
    shpfunc.Compute (integs);

    // Test each integ point
    for (std::size_t index = 0; index < integs.size (); ++index) 
    {
        const auto& DNDxiSet = shpfunc.GetShapeFunctionDerivative (index);
        const auto& integPoint = integs[index];
        
        // Check DNDxi matrix
        ASSERT_NEAR (DNDxiSet (0, 0), -2.0 * integPoint.m_x, TOLERANCE);
        ASSERT_NEAR (DNDxiSet (1, 0), 0.0, TOLERANCE);
        ASSERT_NEAR (DNDxiSet (0, 1), 0.0, TOLERANCE);
        ASSERT_NEAR (DNDxiSet (1, 1), -2.0 * integPoint.m_y, TOLERANCE);
    }
}